/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include "powermanager.h"

#include <QTimer>
#include "vreptest.h"
#include "testform.h"
#include "motionform.h"
#include "fleetdefine.h"


class FileBackupManageDlg;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(PowerManager *p_powerMangerIn,QWidget *parent = 0);
    ~MainWindow();
public:
    int showMotionForm();
    int setDebugFlag(int debugFlagIn);
    int setMainVersion(string versionIn,string dateIn);
private slots:
    void on_pushButton_quick_stop_clicked();
    void on_spinBox_time_valueChanged(int arg1);
    void on_checkBox_on_off_toggled(bool checked);
    void on_pushButton_run_clicked();
    void on_pushButton_open_file_clicked();
    void on_pushButton_default_clicked();
    void on_pushButton_stop_clicked();
    void on_pushButton_clear_clicked();
    void on_spinBox_uf_valueChanged(int arg1);
    void on_spinBox_ut_valueChanged(int arg1);
    void on_spinBox_manual_speed_valueChanged(int arg1);
    void on_pushButton_jog_run_2_pressed();
    void on_pushButton_jog_run_2_released();
    void on_pushButton_jog_run_3_pressed();
    void on_pushButton_jog_run_3_released();
    void on_pushButton_stop_2_clicked();
    void on_spinBox_vrep_speed_valueChanged(int arg1);
    void on_pushButton_setZeroPoint_clicked();
    void on_pushButton_gohome_clicked();
    void on_spinBox_auto_speed_valueChanged(int arg1);
    void on_comboBox_runMode_currentIndexChanged(int index);
    void on_comboBox_moveType_currentIndexChanged(int index);
    void on_checkBox_toggled(bool checked);
    void on_checkBox_io_toggled(bool checked);
    void on_pushButton_clicked();
    void on_pushButton_2_clicked();
    void on_pushButton_3_clicked();
    void on_pushButton_4_clicked();
    void on_pushButton_5_clicked();
    void on_pushButton_6_clicked();
    void on_comboBox_axis_2_currentIndexChanged(int index);
    void on_checkBox_on_off_clicked();
    void on_pushButton_7_clicked();
    void on_pushButton_8_clicked();
    void on_pushButton_9_clicked();
    void on_pushButton_10_clicked();
    void on_pushButton_12_clicked();
    void on_pushButton_13_clicked();
    void on_pushButton_14_clicked();
    void on_pushButton_read_sdo_clicked();
    void on_pushButton_write_sdo_clicked();
    void on_pushButton_clearBatteryError_clicked();
    void on_pushButton_singleAxisCalibrate_clicked();
    void on_pushButton_enable_shutdown_clicked();
    void on_pushButton_disable_shutdown_clicked();
    void on_pushButton_moveZeroPoint_clicked();
    void on_pushButton_writeAlias_clicked();
    void on_pushButton_getSlavesInfo_clicked();
    void on_checkBox_enableNoCalibrateJog_clicked();
    void on_pushButton_getCalibrateInfo_clicked();
    void on_pushButton_run_all_clicked();
    void on_pushButton_cease_all_clicked();
    void on_pushButton_stop_all_clicked();
    void on_pushButton_setAllT1_clicked();
    void on_pushButton_setAllAuto_clicked();
    void on_comboBox_robotId_currentIndexChanged(int index);
    void on_pushButton_read_sdo_2_clicked();
    void on_pushButton_setTorqueFilter_clicked();
    void on_pushButton_goZeroRobot_clicked();
    void on_pushButton_goZeroOneRobot_clicked();
    void on_pushButton_ceaseReturingZero_clicked();
    void on_pushButton_agvTest_clicked();
    void on_pushButton_loadMap_2_clicked();
    void on_pushButton_browseFile_clicked();
    void on_pushButton_createMapStart_clicked();
    void on_pushButton_createMapStop_clicked();
    void on_pushButton_setMapSolver_clicked();
    void on_pushButton_addVitrualBlock_clicked();
    void on_pushButton_deleteVitrualBlock_clicked();
    void on_pushButton_setOdomSolver_clicked();
    void on_pushButton_setLocationSolver_clicked();
    void on_pushButton_getVehiclePosition_clicked();
    void on_pushButton_setVehiclePosition_clicked();
    void on_pushButton_setTrajectoryGlobalPlanSolver_clicked();
    void on_pushButton_setTrajectoryLocalPlanSolver_clicked();
    void on_pushButton_moveToPosition_2_clicked();
    void on_pushButton_start_clicked();
    void on_pushButton_cease_clicked();
    void on_pushButton_stop_3_clicked();
    void on_pushButton_changeVelocity_2_clicked();
    void on_pushButton_15_clicked();
    void on_pushButton_forceQuit_clicked();
    void on_pushButton_ultrasonicPowerNoise_clicked();
    void on_pushButton_browser_program_files_clicked();
    void on_pushButton_calibrate_agv_offset_clicked();
    void on_pushButton_clear_custom_odom_clicked();
    void on_checkBox_ultrasonic_check_status_command_clicked(bool checked);
    void on_checkBox_ultrasonic_check_pointCloud_command_clicked();
    void on_pushButton_resetMasterTimeMeasure_clicked();
    void on_pushButton_vehicle_moveToPosition_clicked();
    void on_pushButton_setDefaultMap_clicked();
    void on_pushButton_modifyFileDirAuthority_clicked();
    void on_pushButton_ultrasonic_change_id_clicked();
    void on_pushButton_get_serialPorInfo_clicked();
    void on_pushButton_16_clicked();
    void on_pushButton_setMainWindowDebugFlag_clicked();
    void on_pushButton_setUltrasonicSensorDebugFlag_clicked();
    void on_pushButton_setNewTime_clicked();
    void on_pushButton_clearBatteryErrorByAxis_clicked();

public slots:
    void timeOut_slot();
    void move_slot();

private:
    void showUltrasonicInfo();
    void showDebugInfo();
    void showPoitionInfo(UpdateDataLv2 &updateDataLv2);
    void showProgramRunningInfo(UpdateDataLv2 &updateDataLv2);
    void showDebugInfo_motionServer(MotionDebugInfo info);
    void showDebugInfo_virtualLineControl(VirtualLineDebugInfo info);
    void showDebugInfo_taskInfo(TaskManagerInfo taskInfo);
    void showDebugInfo_programEngine(std::vector<ProgramEngineDebugInfo> infoList);
    void showDebugInfo_ethercat(EthercatDebugInfo info);
    void showDebugInfo_can(EthercatDebugInfo info);
    void showDebugInfo_modbus(EthercatDebugInfo info);
    void showBatteryInfo(BatteryInformation batteryInfo);
    void showDebugInfo_fleet(FleetDebugInfo info);
    void showVehicleInfo();
    void showStorageInfo();
    void showMessageInfo();
    void showMotorStatusInfo();
    void showPointCloudSafeRatio(std::vector<std::string > &sensorNameOut,std::vector<double> &sensorSafeRatioOut);
    void showFleetInfo();

public:
    testForm* ecatForm;
    VrepTest *vrepForm;

private:
    Ui::MainWindow *ui;
    FileBackupManageDlg *filebackDlg;
    int timerTickCount;

    int choose_axis;
    int robotId;
    int messageSize;
    bool servoOnState;

    QTimer* timer;
    QTimer* timer2;
    bool dir;//方向
    int pos;
    bool jogOnFlag;

    PowerManager *p_powerManger;

    UserInfo userInfo;//ENUM_POWER_ADMIN
    QStandardItemModel* model_batteryInfo;
    QStandardItemModel* model_taskInfo;
    QStandardItemModel* model_progremEngine;
    QStandardItemModel* model_motionEngine;
    QStandardItemModel* model_virtualLineControl;
    QStandardItemModel* model_ethercatSlavesInfo;
    QStandardItemModel* model_axisgroupCalibrateInfo;
    QStandardItemModel* model_ecatDebugInfo;
    QStandardItemModel* model_canDebugInfo;
    QStandardItemModel* model_modbusDebugInfo;
    QStandardItemModel* model_poindCloudSafeInfo;
    QStandardItemModel* model_fleetDebugInfo;
    int debugFlag;
    string oldRuningProgramName;

};

#endif // MAINWINDOW_H
